const tree = require('./tree');

const rightSideView = function(root) {
	let result = [];
	const traverse = (node, deep, res) => {
		if (node == null) {
			return res;
		}
		res[deep] = node.val;
		traverse(node.left, deep + 1, res);
		traverse(node.right, deep + 1, res);
	}
	traverse(root, 0, result);
	return result;
}

const rightSideViewResult = rightSideView(tree);

console.log(rightSideViewResult); // [ 11, 15, 20, 25 ]